from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-22 14:12:54.551062
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 22, Sep, 2021
Time: 14:13:04
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.3024
Nobs: 422.000 HQIC: -46.8242
Log likelihood: 4652.70 FPE: 3.28475e-21
AIC: -47.1651 Det(Omega_mle): 2.66049e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.435512 0.092467 4.710 0.000
L1.Burgenland 0.103517 0.047756 2.168 0.030
L1.Kärnten -0.114219 0.023880 -4.783 0.000
L1.Niederösterreich 0.155529 0.102188 1.522 0.128
L1.Oberösterreich 0.118283 0.100354 1.179 0.239
L1.Salzburg 0.284387 0.050125 5.674 0.000
L1.Steiermark 0.030650 0.066564 0.460 0.645
L1.Tirol 0.108600 0.052804 2.057 0.040
L1.Vorarlberg -0.104320 0.047204 -2.210 0.027
L1.Wien -0.011225 0.091662 -0.122 0.903
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013027 0.212372 0.061 0.951
L1.Burgenland -0.050621 0.109682 -0.462 0.644
L1.Kärnten 0.037078 0.054845 0.676 0.499
L1.Niederösterreich -0.215440 0.234700 -0.918 0.359
L1.Oberösterreich 0.486647 0.230487 2.111 0.035
L1.Salzburg 0.306758 0.115123 2.665 0.008
L1.Steiermark 0.115125 0.152881 0.753 0.451
L1.Tirol 0.314698 0.121276 2.595 0.009
L1.Vorarlberg 0.001976 0.108416 0.018 0.985
L1.Wien 0.002391 0.210523 0.011 0.991
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.245012 0.046875 5.227 0.000
L1.Burgenland 0.090601 0.024209 3.742 0.000
L1.Kärnten -0.001915 0.012106 -0.158 0.874
L1.Niederösterreich 0.211912 0.051804 4.091 0.000
L1.Oberösterreich 0.164468 0.050874 3.233 0.001
L1.Salzburg 0.035166 0.025410 1.384 0.166
L1.Steiermark 0.019442 0.033744 0.576 0.565
L1.Tirol 0.068578 0.026768 2.562 0.010
L1.Vorarlberg 0.057701 0.023930 2.411 0.016
L1.Wien 0.110613 0.046467 2.380 0.017
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183798 0.045951 4.000 0.000
L1.Burgenland 0.047085 0.023732 1.984 0.047
L1.Kärnten -0.006634 0.011867 -0.559 0.576
L1.Niederösterreich 0.140169 0.050782 2.760 0.006
L1.Oberösterreich 0.318289 0.049871 6.382 0.000
L1.Salzburg 0.100872 0.024909 4.050 0.000
L1.Steiermark 0.130088 0.033079 3.933 0.000
L1.Tirol 0.076676 0.026241 2.922 0.003
L1.Vorarlberg 0.055335 0.023458 2.359 0.018
L1.Wien -0.045854 0.045551 -1.007 0.314
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207743 0.091103 2.280 0.023
L1.Burgenland -0.048447 0.047051 -1.030 0.303
L1.Kärnten -0.034705 0.023527 -1.475 0.140
L1.Niederösterreich 0.108407 0.100681 1.077 0.282
L1.Oberösterreich 0.165952 0.098874 1.678 0.093
L1.Salzburg 0.252404 0.049385 5.111 0.000
L1.Steiermark 0.081731 0.065582 1.246 0.213
L1.Tirol 0.126315 0.052025 2.428 0.015
L1.Vorarlberg 0.114999 0.046508 2.473 0.013
L1.Wien 0.029549 0.090310 0.327 0.744
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.032046 0.070463 0.455 0.649
L1.Burgenland 0.023177 0.036392 0.637 0.524
L1.Kärnten 0.052616 0.018197 2.891 0.004
L1.Niederösterreich 0.210150 0.077872 2.699 0.007
L1.Oberösterreich 0.333188 0.076474 4.357 0.000
L1.Salzburg 0.046470 0.038197 1.217 0.224
L1.Steiermark -0.004425 0.050725 -0.087 0.930
L1.Tirol 0.113365 0.040238 2.817 0.005
L1.Vorarlberg 0.066347 0.035972 1.844 0.065
L1.Wien 0.127965 0.069850 1.832 0.067
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183812 0.085879 2.140 0.032
L1.Burgenland 0.017940 0.044354 0.404 0.686
L1.Kärnten -0.057347 0.022178 -2.586 0.010
L1.Niederösterreich -0.117965 0.094908 -1.243 0.214
L1.Oberösterreich 0.185720 0.093205 1.993 0.046
L1.Salzburg 0.030760 0.046554 0.661 0.509
L1.Steiermark 0.296991 0.061822 4.804 0.000
L1.Tirol 0.489106 0.049042 9.973 0.000
L1.Vorarlberg 0.078073 0.043841 1.781 0.075
L1.Wien -0.104745 0.085132 -1.230 0.219
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159357 0.094110 1.693 0.090
L1.Burgenland -0.012335 0.048604 -0.254 0.800
L1.Kärnten 0.063925 0.024304 2.630 0.009
L1.Niederösterreich 0.195552 0.104004 1.880 0.060
L1.Oberösterreich -0.126602 0.102137 -1.240 0.215
L1.Salzburg 0.236114 0.051015 4.628 0.000
L1.Steiermark 0.153575 0.067747 2.267 0.023
L1.Tirol 0.046861 0.053742 0.872 0.383
L1.Vorarlberg 0.131861 0.048043 2.745 0.006
L1.Wien 0.154030 0.093291 1.651 0.099
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.485630 0.051023 9.518 0.000
L1.Burgenland -0.007285 0.026351 -0.276 0.782
L1.Kärnten -0.009863 0.013177 -0.749 0.454
L1.Niederösterreich 0.200801 0.056387 3.561 0.000
L1.Oberösterreich 0.257944 0.055375 4.658 0.000
L1.Salzburg 0.022178 0.027659 0.802 0.423
L1.Steiermark -0.022027 0.036730 -0.600 0.549
L1.Tirol 0.067247 0.029137 2.308 0.021
L1.Vorarlberg 0.060724 0.026047 2.331 0.020
L1.Wien -0.052507 0.050579 -1.038 0.299
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021769 0.077687 0.139723 0.131123 0.044324 0.077193 0.000407 0.182244
Kärnten 0.021769 1.000000 -0.044321 0.128458 0.046962 0.069372 0.454968 -0.092050 0.091437
Niederösterreich 0.077687 -0.044321 1.000000 0.282213 0.081983 0.264131 0.022408 0.137726 0.259381
Oberösterreich 0.139723 0.128458 0.282213 1.000000 0.177867 0.285151 0.155909 0.101829 0.137048
Salzburg 0.131123 0.046962 0.081983 0.177867 1.000000 0.124562 0.056079 0.106006 0.050572
Steiermark 0.044324 0.069372 0.264131 0.285151 0.124562 1.000000 0.132080 0.091939 -0.021017
Tirol 0.077193 0.454968 0.022408 0.155909 0.056079 0.132080 1.000000 0.045692 0.120747
Vorarlberg 0.000407 -0.092050 0.137726 0.101829 0.106006 0.091939 0.045692 1.000000 -0.046586
Wien 0.182244 0.091437 0.259381 0.137048 0.050572 -0.021017 0.120747 -0.046586 1.000000